import 'package:flutter/material.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lib_uikit/widgets/gt_dashed_line_text.dart';

///默认defaultType左边浅色文字，右边深色文字;
///lightText 左边右边都是浅色文字text3
///darkText 左边右边都是深色文字text1
enum GTDescriptionTypeV3 { defaultType, lightText, darkText }

///Descriptions 描述列表
class GTDescriptionV3 extends StatelessWidget {
  final List<GTDescriptionModalV3> list;
  final String? title;
  final GTDescriptionTypeV3? type;
  final ScrollPhysics? scrollPhysics;

  ///Collapse组件专用！
  final bool? smallStyle;

  const GTDescriptionV3({
    super.key,
    required this.list,
    this.title,
    this.type = GTDescriptionTypeV3.defaultType,
    this.smallStyle,
    this.scrollPhysics,
  });

  @override
  Widget build(BuildContext context) {
    double paddingVertical = 16, titleSize = 16;

    if (smallStyle ?? false) {
      paddingVertical = 12;
      titleSize = 12;
    }
    return Container(
      padding: EdgeInsets.symmetric(vertical: paddingVertical, horizontal: 12),
      decoration: BoxDecoration(color: GTColorsV3.card1.color, borderRadius: BorderRadius.circular(3)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          if ((title ?? "").isNotEmpty) ...[
            Text(
              title ?? "",
              style: gtTextStyleW500(fontSize: titleSize, color: GTColorsV3.text1.color),
            ),
            const SizedBox(
              height: 12,
            ),
          ],
          _list(context)
        ],
      ),
    );
  }

  Widget _list(BuildContext context) {
    return MediaQuery.removePadding(
        context: context,
        removeTop: true,
        removeBottom: true,
        child: ListView.separated(
          separatorBuilder: (context, index) => const SizedBox(height: 12),
          itemCount: list.length,
          shrinkWrap: true,
          physics: scrollPhysics ?? const NeverScrollableScrollPhysics(),
          itemBuilder: (context, index) {
            return _listItem(list[index]);
          },
        ));
  }

  Widget _listItem(GTDescriptionModalV3 data) {
    Color startColor, endColor;
    switch (type) {
      case GTDescriptionTypeV3.defaultType:
        startColor = GTColorsV3.text3.color;
        endColor = GTColorsV3.text1.color;
        break;
      case GTDescriptionTypeV3.lightText:
        startColor = GTColorsV3.text3.color;
        endColor = GTColorsV3.text3.color;
        break;
      case GTDescriptionTypeV3.darkText:
        startColor = GTColorsV3.text1.color;
        endColor = GTColorsV3.text1.color;
        break;
      default:
        startColor = GTColorsV3.text3.color;
        endColor = GTColorsV3.text1.color;
        break;
    }
    return Row(
      children: [
        Expanded(
          child: GestureDetector(
              onTap: data.onTitleClicked,
              child: GTDashedLineText(
                text: data.startText,
                textStyle: gtTextStyleW400(color: startColor, fontSize: (smallStyle ?? false) ? 11 : 14),
                onDashedTextClick: null,
                showDashedLine: data.showDashedLine ?? false,
              )),
        ),
        const SizedBox(
          width: 12,
        ),
        Text(
          data.endText.isNotEmpty ? data.endText : "--",
          style: gtTextStyleW500(color: endColor, fontSize: (smallStyle ?? false) ? 11 : 14),
        ),
        if (data.endIcon != null) ...[
          const SizedBox(
            width: 8,
          ),
          Icon(
            data.endIcon,
            color: endColor,
            size: 16,
          ),
        ]
      ],
    );
  }
}

class GTDescriptionModalV3 {
  final String startText;
  final String endText;
  final bool? showDashedLine;
  final IconData? endIcon;
  final VoidCallback? onTitleClicked;

  GTDescriptionModalV3(
      {required this.startText, required this.endText, this.showDashedLine, this.endIcon, this.onTitleClicked});
}
